<?php
require_once 'connexion (2).php';
//require_once 'fonction.php';
//require_once 'telech.php';
include'recuperation.php';

recupIdPersonne("Moussa Ben", "eleve");
?>
<?php
        
       $idstage=null;
        if(!(isset($_GET['idstage'])))
        {
            echo '';
        }else{
            $idstage=$_GET['idstage'];
           
        }
        
        
        $action=null;
        if(!(isset($_GET['action'])))
        {
            print("");
        }else{
            $action=$_GET['action'];
            }
        
    
        ?>   
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" href="feuilledestyle.css">
        <link rel="stylesheet" href="menuHead/jquery.cleditor.css">
        <link href="menu2/styles.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="verifAj.js"> </script>
        <script type="text/javascript" src="verifMod.js"> </script>
        <script type="text/javascript" src="ajax/recupSaisieEleve.js"> </script>
        <script type="text/javascript" src="ajax/recupSaisieEnse.js"> </script>
        
    </head>
    <body vlink="blue">
        <div id="page">
        <?php include 'header.php';?>
        <div id="cadre">
        <?php include 'menu.php';?>
          <FORM style="float:left; margin-top: 20px; background-color: orange; "> <INPUT TYPE="button" VALUE="Retour" onClick="history.back()"> </FORM> 
<?php


$referer=$_SERVER['HTTP_REFERER'];

if($action=="ajouter")
{
                
    if($_SESSION['mail'])
    { 
        
                
?>          <div class="centre">
                
                <br> 
                <h3>Ajouter un offre de stage</h3>
               
            </div>
                <div class="centre">
                    <br>
                    <?php //$idMS=$_SESSION['mail'];
        $requete="select * from personne as p, maitrestage as m, entreprise as e where e.IDENTREPRISE=m.IDENTREPRISE and m.IDMAITRESTAGE=p.IDPERSONNE and MAILPERSONNE='".$_SESSION['mail']."'";
        $recup=$connexion->query($requete);
         $r="";
        if($r=$recup->fetch(PDO::FETCH_ASSOC))
        {                
            echo '<FORM action="inserer.php?idEN='.$r['IDENTREPRISE'].'" method="POST">';}}
                    ?>
                    <table border="12" class="petitformdata" align="center" style="background-color:#CCC;  color: slategray; max-width:600px;">
                              
                        <tr>
                            <th>Date début (*): </th>
                            <?php
                            
                            $a=date("Y");
                            
                            echo '<td><select name="jrdd" id="jrdd" onChange="verifDateA();">';
                            for($i=1;$i<32;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="modd" id="modd" onChange="verifDateA()">';
                            for($i=1;$i<13;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="andd" id="andd" onChange="verifDateA()">';
                            for($i=$a;$i<$a+20;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            echo '</select></td>';
                               ?>      
                            
                        </tr>
                        <tr>
                            <th>Date fin (*): </th>
                             <?php
                            $a1=date("Y");
                            
                            echo '<td><select name="jrdf" id="jrdf" onChange="verifDateA()">';
                            for($i=1;$i<32;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="modf" id="modf" onChange="verifDateA()">';
                            for($i=1;$i<13;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="andf" id="andf" onChange="verifDateA()">';
                            for($i=$a1;$i<$a1+20;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            echo '</select></td>';
                               ?>      
                           
                        </tr>
                        
                        <tr>
                            <th>Sujet stage : </th>
                            <td><textarea cols="35" rows="4" name="sujSA" id="sujSA" onKeyup="verifDateA()"></textarea></td>
                        </tr>
                                <?php 
                                  echo '<tr>
                                  <th style="float:leftd;">Formation :</th>
                                  <td style="float:leftd;"><select name="formSA" id="formSA" onBlur="envoyerRequeteEn(this.value);" onChange="envoyerRequeteEl(this.value);" ><option value=""></option>';
                                              
                                  $req_rando="select * from formation";
                                  $resu_ra=$connexion->query($req_rando);
                                              
                                  while ($rep=$resu_ra->fetch(PDO::FETCH_ASSOC))
                                        {
                                          $idF=$rep["IDFORMATION"];
                                          $descF=$rep["LIBELLEFORMATION"]; 
                                          echo '<option value="'.$idF.'">'.$descF.'</option>';
                                        }
                                          echo ' </td>
                                          </tr>';
                                                 
                                ?>
                        
                        <tr>
                            <th></th>
                            <td><h5 id="btInsA"></h5></td>
                        </tr>
                               
                            </table>
                        </FORM>
                </div>
<?php
}else
if($action=="modifier")
{
                
?>
                <div class="centre">

                     <br> 
                     <h3>Modifier l'offre de stage</h3>

                 </div>
                 <div class="centre">
                    <br>
                    
                      <?php //$idMS=$_SESSION['mail'];
        $requete="select * from personne as p, maitrestage as m, entreprise as e where e.IDENTREPRISE=m.IDENTREPRISE and m.IDMAITRESTAGE=p.IDPERSONNE and MAILPERSONNE='".$_SESSION['mail']."'";
        $recup=$connexion->query($requete);
         $r="";
        if($r=$recup->fetch(PDO::FETCH_ASSOC))
        {    
            
            ?>             
            <FORM action="inserer.php?idEN=<?php echo $r['IDENTREPRISE'];?>&action=modifier&idStage=<?php echo $idstage;?>" method="POST" ><?php }?>
                    
                    <table border="12" align="center"  class="petitformdata"  style="background-color:#CCC; color: slategray; max-width:600px;" >
                             <?php 
                             
                                    $req_mo="select * from stage as s, formation as f where s.IDFORMATION=f.IDFORMATION 
                                             and IDSTAGE=".$idstage;
                                   $resu_m=$connexion->query($req_mo);
                                              
                                   if ($repm=$resu_m->fetch(PDO::FETCH_ASSOC))
                                         {
                                            $DD=$repm["DATEDEBUT"];
                                            list($ad, $md, $jd) = explode("-", $DD); 
                                            $DF=$repm["DATEFIN"]; 
                                            list($af, $mf, $jf) = explode("-", $DF);
                                            $ETA=$repm["ETATSTAGE"]; 
                                            $SJ=$repm["SUJETSTAGE"]; 
                                            $FT=$repm["LIBELLEFORMATION"];
                                            
                                ?>  
                                <tr>
                                  
                            <th>Date début (*): </th>
                            <?php
                            
                            $a2=date("Y");
                            
                            echo '<td><select name="jrdd" id="jrdd" onChange="verifDateM();"><option value="'.$jd.'">'.$jd.'</option>';
                            for($i=1;$i<32;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="modd" id="modd" onChange="verifDateM()"><option value="'.$md.'">'.$md.'</option>';
                            for($i=1;$i<13;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="andd" id="andd" onChange="verifDateM()"><option value="'.$ad.'">'.$ad.'</option>';
                            for($i=$a2;$i<$a2+30;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            echo '</select></td>';
                               ?>      
                            
                        </tr>
                        <tr>
                            <th>Date fin (*): </th>
                             <?php
                            $a=date("Y");
                            
                            echo '<td><select name="jrdf" id="jrdf" onChange="verifDateM()"><option value="'.$jf.'">'.$jf.'</option>';
                            for($i=1;$i<32;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="modf" id="modf" onChange="verifDateM()"><option value="'.$mf.'">'.$mf.'</option>';
                            for($i=1;$i<13;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            
                            echo '</select><select name="andf" id="andf" onChange="verifDateM()"><option value="'.$af.'">'.$af.'</option>';
                            for($i=$a;$i<$a+30;$i++)
                            {
                            echo '<option value="'.$i.'">'.$i.'</option>';
                            }
                            echo '</select></td>';
                               ?>      
                           
                        </tr>
                        <tr>
                            <th>Etat stage (*): </th>
                            <td><select name="etats" id="etats" onChange="verifDateM()">
                                    <option value="<?php ECHO $ETA; ?>"><?php  ECHO $ETA; ?></option> 
                                    <option value="En Attente">En attente</option>
                                    <option value="Affecté">Affecté</option>
                                    <option value="Réalisé">Réalisé</option>
                                    <option value="Annulé">Annulé</option>
                            </select></td>
                        </tr>
                        <tr>
                            <th>Sujet stage : </th>
                            <td><textarea cols="35" rows="4" name="sujS" id="sujS" onKeyup="verifDateM()"><?php echo$SJ; ?></textarea></td>
                        </tr>
                       
                                <?php 
                                  echo '<tr>
                                  <th style="float:leftd;">Formation :</th>
                                  <td style="float:leftd;"><select name="form" id="form" onBlur="envoyerRequeteEn(this.value);" onChange="envoyerRequeteEl(this.value);" ><option value="'.$repm["IDFORMATION"].'">'.$FT.'</option>';
                                              
                                  $req_rando="select * from formation";
                                  $resu_ra=$connexion->query($req_rando);
                                              
                                  while ($rep=$resu_ra->fetch(PDO::FETCH_ASSOC))
                                        {
                                          $idF=$rep["IDFORMATION"];
                                          $descF=$rep["LIBELLEFORMATION"]; 
                                          echo '<option value="'.$idF.'">'.$descF.'</option>';
                                        }
                                          echo ' </td>
                                          </tr>';
                                         }             
                                ?>
                        
                        <tr>
                            <th></th>
                            <td><h5 id="btIns"></h5></td>
                        </tr>
                               
                  </table>
            </form>
                </div>
            
            <?php }
            else
                    if($action=="supprimer")
                    {
                            $suppC="delete from compterendu where IDSTAGE=".$idstage;
                            $exeC=$connexion->exec($suppC); 
                            
                            $suppS="delete from stage where IDSTAGE=".$idstage;
                            $exeS=$connexion->exec($suppS);
                            header("Location: ".$referer);
                    }
?> 
                <?php require_once 'pied.php';?>
        </div>
        </div>
    </body>
</html>